/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.activity.vo.CnDiscountShopVoReq;
import com.ykht.proj.activity.vo.VDiscountPlanVo;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.activity.entity.VDiscountPlanShop;
import com.ykht.proj.activity.service.VDiscountPlanShopService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 优惠方案和门店关联表
 *
 * @author csg
 * @date 2021-05-18 14:26:34
 */
@RestController
@AllArgsConstructor
@RequestMapping("/vdiscountplanshop")
@Api(value = "vdiscountplanshop", tags = "优惠方案和门店关联表管理")
@Slf4j
public class VDiscountPlanShopController {

	private final VDiscountPlanShopService vDiscountPlanShopService;

	/**
	 * 门店方案记录分页查询
	 *
	 * @param page            分页对象
	 * @param vDiscountPlanVo 优惠方案和门店关联表
	 * @return
	 */
	@ApiOperation(value = "门店方案记录分页查询", notes = "门店方案记录分页查询")
	@GetMapping("/page")
//	@PreAuthorize("@pms.hasPermission('activity_vdiscountplanshop_view')")
	public R getVDiscountPlanShopPage(Page page, VDiscountPlanVo vDiscountPlanVo) {
		log.info("->门店方案记录分页查询{}", vDiscountPlanVo);
		IPage<VDiscountPlanVo> planVoIPage = vDiscountPlanShopService.getVDiscountPlanShopPage(page, vDiscountPlanVo);
		return R.ok(planVoIPage);
	}


	/**
	 * 通过id查询优惠方案和门店关联表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('activity_vdiscountplanshop_view')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(vDiscountPlanShopService.getById(id));
	}

	/**
	 * 新增优惠方案和门店关联表
	 *
	 * @param vDiscountPlanShop 优惠方案和门店关联表
	 * @return R
	 */
	@ApiOperation(value = "新增优惠方案和门店关联表", notes = "新增优惠方案和门店关联表")
	@SysLog("新增优惠方案和门店关联表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('activity_vdiscountplanshop_add')")
	public R save(@RequestBody VDiscountPlanShop vDiscountPlanShop) {
		return R.ok(vDiscountPlanShopService.save(vDiscountPlanShop));
	}

	/**
	 * 修改优惠方案和门店关联表
	 *
	 * @param vDiscountPlanShop 优惠方案和门店关联表
	 * @return R
	 */
	@ApiOperation(value = "修改优惠方案和门店关联表", notes = "修改优惠方案和门店关联表")
	@SysLog("修改优惠方案和门店关联表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('activity_vdiscountplanshop_edit')")
	public R updateById(@RequestBody VDiscountPlanShop vDiscountPlanShop) {
		return R.ok(vDiscountPlanShopService.updateById(vDiscountPlanShop));
	}

	/**
	 * 通过id删除优惠方案和门店关联表
	 *
	 * @param id id
	 * @return R
	 */
	@ApiOperation(value = "通过id删除优惠方案和门店关联表", notes = "通过id删除优惠方案和门店关联表")
	@SysLog("通过id删除优惠方案和门店关联表")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('activity_vdiscountplanshop_del')")
	public R removeById(@PathVariable Long id) {
		return R.ok(vDiscountPlanShopService.removeById(id));
	}


	/**
	 * 获取 创建优惠方案获取门店列表（根据品牌id, 门店名, 地址查询)
	 *
	 * @param cnDiscountShopVoReq 优惠方案和门店关联表
	 * @return R
	 */
	@ApiOperation(value = "获取 创建优惠方案获取门店列表（根据品牌id, 门店名, 地址查询)", notes = "获取 创建优惠方案获取门店列表（根据品牌id, 门店名, 地址查询)")
	@SysLog("获取 创建优惠方案获取门店列表（根据品牌id, 门店名, 地址查询)")
	@PostMapping("getByDiscountPlanShop")
	public R<List<CnDiscountShopVoReq>> getByDiscountPlanShop(@RequestBody CnDiscountShopVoReq cnDiscountShopVoReq) {
		List<CnDiscountShopVoReq> cnDiscountShopVoReqList = vDiscountPlanShopService.getByDiscountPlanShop(cnDiscountShopVoReq);
		return R.ok(cnDiscountShopVoReqList);
	}


}
